package Gui;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Line;
import javax.sound.sampled.Mixer;

public class Volume {

	public static void fadeIn(){
		
	}
	
	public static void fadeOut(){

	}
	
	public static void adjustVolume(float value, String s) 
	{ 
		Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo(); 
		for (int i = 0; i < mixerInfos.length; i++) 
		{ 
			Mixer mixer = AudioSystem.getMixer(mixerInfos[i]); 
			Line.Info[] targetLineInfos = mixer.getTargetLineInfo(); 
		
			for (int j = 0; j < targetLineInfos.length; j++) 
			{ 
				setVolume(targetLineInfos[j], value, s); 
			} 
		} 
	} 
	private static void setVolume(Line.Info lineInfo, float value, String s) 
	{ 
		try 
		{ 
			float tempV = -1;
			Line line = AudioSystem.getLine(lineInfo); 
			line.open(); 
		
			FloatControl control = (FloatControl)line.getControl(FloatControl.Type.VOLUME); 
			if(s.equals("Inc")){
				tempV = control.getValue();
				if(tempV > 1){
					tempV = 1;
				}else{
					tempV = (float) (tempV + 0.1);
				}
				control.setValue(tempV); 
				line.close(); 
			}else if(s.equals("Dec")){
				tempV = control.getValue();
				if(tempV < 0){
					tempV = 1;
				}else{
					tempV = (float) (tempV - 0.1);
				}
				control.setValue(tempV); 
				line.close(); 
			}else{
				control.setValue(value); 
				line.close(); 
			}
		} 
		catch(Exception e) {} 
	}
}
